package com.qdaily.supportlibrary.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import com.qdaily.supportlibrary.util.LocalDisplay;
import com.qdailylibrary.R;

import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

/**
 * Created by song on 15/5/14.
 */
public class PageLoadingView extends Dialog {

    private Context context;
    private GifImageView gifView;
    private GifDrawable gifDrawable;

    public PageLoadingView(Context context) {
        this(context, R.style.loading_dialog);
        // TODO Auto-generated constructor stub
        this.context = context;
    }

    public PageLoadingView(Context context, int theme) {
        super(context, theme);
        this.context = context;

        this.setContentView(R.layout.loading);

        gifView = (GifImageView)findViewById(R.id.gif2);
        gifView.setImageResource(R.drawable.pageloading);
        gifDrawable = (GifDrawable)gifView.getDrawable();
        Window dialogWindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        lp.width = LocalDisplay.SCREEN_WIDTH_PIXELS; // 宽度
        lp.height = LocalDisplay.SCREEN_HEIGHT_PIXELS; // 高度

        dialogWindow.setAttributes(lp);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    public void clear() {

    }

    @Override
    public void show() {
        try {
            super.show();
        } catch (Exception e) {

        }
    }

    @Override
    public void dismiss() {
        if (gifView != null)
        {
            gifView.setImageBitmap(null);
            gifView.setImageDrawable(null);
            gifDrawable.recycle();
            gifDrawable = null;
            gifView = null;
        }
        super.dismiss();
    }

}